package com.factory.absfactory.order;

import com.factory.absfactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/4/13 12:43
 */
public class OrderPizza {
    
    private AbsFactory factory;
    
    public OrderPizza(AbsFactory factory){
        setFactory(factory);
    }
    
    private void setFactory(AbsFactory factory){
        // factory可能是BJFactory LDFactory 具体看传入什么
        this.factory = factory;
        Pizza pizza = null;
        String orderType = "";
        
        do {
            orderType = getType();
            pizza = factory.createPizza(orderType);
            if (pizza != null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购失败");
                break;
            }
        } while (true);
    }


    // 写一个方法，可以动态的获取客户希望订购的披萨种类
    private String getType(){
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = br.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
    
}
